package cn.mily.org.controller;


import cn.mily.basics.utils.IdAndNameUtildomain;
import cn.mily.basics.utils.JsonResult;
import cn.mily.org.domain.Shop;
import cn.mily.org.domain.ShopErrorMsg;
import cn.mily.org.service.IShopErrorService;
import cn.mily.org.service.IShopService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@RequestMapping("/shoperror")
public class ShopErrorController {

    @Autowired
    private IShopErrorService service;

    @Autowired
    private IShopService shopServices;

    /*添加错误信息商店*/
    @PutMapping
    public JsonResult add(@RequestBody ShopErrorMsg errorMsg){
        try {
            service.add(errorMsg);
            Long id = errorMsg.getShop_id();
            Shop s = new Shop();
            s.setId(id);
            s.setState(0);
            shopServices.updateState(s);
            return new JsonResult();
        } catch (Exception e) {
            e.printStackTrace();
            return new JsonResult("操作失败！");
        }
    }

    /*根据店铺id获取错误信息*/
    @GetMapping("/{id}")
    public ShopErrorMsg getErrorMsg(@PathVariable Long id){
        return service.findOne(id);
    }

    /*获取全部驳回类型*/
    @PostMapping("/type")
    public List<IdAndNameUtildomain> getType(){
        return service.findType();
    }

}
